package com.bridgeintelligent.tag.user.query.web;


import com.bridgeintelligent.tag.user.mgmt.entity.Result;
import com.bridgeintelligent.tag.user.mgmt.pojo.User;
import com.bridgeintelligent.tag.user.query.service.UserQueryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "用户查询")
@RestController
@RequestMapping("/api/user")
public class UserQueryController {

    @Autowired
    private UserQueryService UserQueryService;

    /**
     * 根据用户名查询单个用户信息
     *
     * @param username
     * @return
     */
    @ApiOperation("查询单个用户详细信息")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "path", name = "username", value = "用户名", required = true)})
    @GetMapping("/findOneByUsername/{username}")
    public Result findOneByUsername(@PathVariable String username) {

        User user = UserQueryService.findOneByUsername(username);
        return new Result(0, user);
    }

    /**
     * 查询所有用户信息
     *
     * @return
     */
    @ApiOperation("查询所有用户信息")
    @GetMapping("/findAllUser")
    public Result findAllUser() {
        List<User> list = UserQueryService.findAllUser();
        return new Result(0, list);
    }

    /**
     * 查询所有有效用户信息
     *
     * @return
     */
    @ApiOperation("查询所有有效用户信息")
    @GetMapping("/findUserList")
    public Result findUserList() {
        List<User> list = UserQueryService.findUserList();
        return new Result(0, list);
    }

    /**
     * 查询所有有效用户信息
     *
     * @return
     */
    @ApiOperation("查询所有有效用户信息")
    @GetMapping("/findAllUserList")
    public Result findAllUserList() {
        List<User> list = UserQueryService.findAllUserList();
        return new Result(0, list);
    }

    /**
     * 获取用户列表
     *
     * @return
     */
    @ApiOperation("获取用户列表")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "pageNumber", value = "页码"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "条数"),
            @ApiImplicitParam(paramType = "query", name = "name", value = "姓名"),
            @ApiImplicitParam(paramType = "query", name = "userPhone", value = "手机号"),
            @ApiImplicitParam(paramType = "query", name = "userId", value = "用户号")
    })
    @GetMapping("/list")
    public Result list(Integer pageNumber, Integer pageSize, String name, String userPhone, String userId) {
        pageNumber = pageNumber == null ? 1 : pageNumber;
        pageSize = pageSize == null ? 10 : pageSize;
        return UserQueryService.list(pageNumber, pageSize, name, userPhone, userId);
    }

}